const pool = require('../tools/getPool');
const sendResponse = require('../tools/sendResponse');

module.exports = function(req, res){

	// 获取数据库连接
	pool.getConnection(function(err, connection) {
		if (err) {
			sendResponse('error','数据库内部错误', null, res);
			return;
		}
		// 执行语句
		connection.query('SELECT c.id as id, c.able as able, c.createtime as createtime, c.content as content, c.author_id as author_id, news_id, u.account as account, u.name as name, n.title as title FROM comment c LEFT JOIN user u ON c.author_id = u.id LEFT JOIN news n ON c.news_id = n.id  ORDER BY c.createtime DESC;;', function (error, rows, fields) {
			// 释放连接
			connection.release();

			if (error) { 
				sendResponse('error','数据库内部错误', null, res);
				return;
			}

			sendResponse('ok','获取成功', rows, res);

		})	

	});

}